import express from "express";
import cors from "cors";
const __dirname = new URL(".", import.meta.url).pathname;
const app = express();
app.use(express.static(__dirname));
app.use(cors());

app.get("/clock", function (req, res) {
  res.send(new Date().toLocaleString());
});
app.get("/clock2", function (req, res) {
  setInterval(() => {
    res.write(`<script>
        parent.document.getElementById('clock').innerHTML = "${new Date().toLocaleString()}"
    </script>`);
  }, 1000);
});

app.get("/clock3", function (req, res) {
  res.header("Content-Type", "text/event-stream");

  setInterval(() => {
    res.write(`data:${new Date().toLocaleString()}\n\n`);
  }, 1000);
});

app.listen(3000);
